<template>
  <div class="container enroll">
    <div class="user-top-bg"></div>
    <div class="user-main">
      <userinfo
        :userinfo="user"
        :jifen="jifen"
        :chuqin="chuqin"
        :level="level"
        @logined="onRefresh"
      ></userinfo>
    </div>
    <div class="user-menu">
      <van-cell-group
        inset
        :border="false"
      >
        <van-cell
          title="成员认证"
          is-link
          @click="pushNativelink('/pages/userauth/main')"
        />
        <van-cell
          title="会员申请"
          is-link
          @click="pushNativelink('/pages/memberauth/main')"
        />
        <van-cell
          title="积分明细"
          is-link
          @click="pushNativelink('/pages/jifendetail/main')"
        />
        <van-cell
          title="出勤记录"
          is-link
          :border="false"
          @click="pushNativelink('/pages/check/main')"
        />
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import Userinfo from '@/components/user/userinfo'
export default {
  components: {
    Userinfo
  },

  data () {
    return {
      title: '记工客',
      cover1: 'http://oss.youmbe.com/assets/ucenter/background.jpg',
      genderIcon: '',
      assets: {
        avatar: 'http://oss.youmbe.com/assets/avatar/foreman.png'
      },
      showTips: true,
      user: {
        id: 0,
        nickname: '登录/注册',
        gender: 0,
        avatar: 'http://oss.youmbe.com/assets/avatar/foreman.png',
        mobile: '',
        description: '这家伙很懒，什么都没有写~',
        actived: false,
        authented: false,
        wizard: null
      },
      userinfo: {
        avatar: '/static/icons/user_default.png',
        nickname: '游客'
      },
      jifen: '0',
      chuqin: '0',
      level: '-'
    }
  },
  onShow () {
    const userData = mpvue.getStorageSync('mine')
    console.log('用户登录信息：', userData)
    if (userData) {
      this.user = userData
      this.title = userData.nickname
      if (userData.gender === 1) {
        this.genderIcon = '/static/icons/male.png'
      } else if (userData.gender === 2) {
        this.genderIcon = '/static/icons/female.png'
      }
    }
    console.log('user/index onShow', this.user.actived)
  },
  methods: {
    onRefresh () {
      const userData = mpvue.getStorageSync('mine')
      console.log('用户登录信息：', userData)
      if (userData) {
        this.user = userData
        this.title = userData.username
        if (userData.gender === 1) {
          this.genderIcon = '/static/icons/male.png'
        } else if (userData.gender === 2) {
          this.genderIcon = '/static/icons/female.png'
        }
      }
    },
    onAction () {
      if (this.user.wizard.name === 'bind') {
        this.onBind()
      } else if (this.user.wizard.name === 'perfect') {
        this.onShowProfile()
      }
    }
  }
}
</script>

<style lang="less">
.user-top-bg {
  position: fixed;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 150px;
  background: #ee732f;
}
.user-main {
  padding: 20px;
  height: auto;
  position: relative;
  top: 45px;
  margin: 0px 10px;
  border-radius: 5px;
  background-color: #fff;
}
.user-menu {
  padding: 5px;
  height: auto;
  position: relative;
  top: 45px;
  margin: 10px;
  border-radius: 5px;
  background-color: #fff;
}
</style>
